package org.liurq.activemqspring.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class ActiveMQController {

    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;

    @RequestMapping("/sendQueue")
    public String sendQueue(String queue) {
        String msg = UUID.randomUUID().toString();
        jmsMessagingTemplate.convertAndSend(queue,msg );
        System.out.println("发送 " + queue + " :" + msg);
        return "ok";
    }

    @RequestMapping("/sendTopic")
    public String sendTopic(String topic) {
        String msg = UUID.randomUUID().toString();
        jmsMessagingTemplate.convertAndSend(topic, msg);
        System.out.println("发送 " + topic + " :" + msg);
        return "ok";
    }
}
